home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 20
/
Cream of the Crop 20 (Terry Blount) (1996).iso
/
program
/
n_b_v203.zip
/
32BITPTR.DMO
< prev
next >
Wrap
Text File
|
1996-07-04
|
5KB
|
80 lines
$if 0
┌──────────────────────────╖ PowerBASIC v3.20
┌──┤ DASoft ╟──────────────────────┬──────────────────╖
│ ├──────────────────────────╢ Copyright 1995 │ DATE: 1995-10-01 ╟─╖
│ │ FILE NAME 32BITPTR.DMO ║ by ╘════════════════─ ║ ║
│ │ ║ Don Schullian, Jr. ║ ║
│ ╘══════════════════════════╝ ║ ║
│ A license is hereby granted to the holder to use this source code in ║ ║
│ any program, commercial or otherwise, without receiving the express ║ ║
│ permission of the copyright holder and without paying any royalties, ║ ║
│ as long as this code is not distributed in any compilable format. ║ ║
│ IE: source code files, PowerBASIC Unit files, and printed listings ║ ║
╘═╤═════════════════════════════════════════════════════════════════════╝ ║
│ .................................... ║
╘═══════════════════════════════════════════════════════════════════════╝
Many of the SUBs and FUNCTIONs in this library work with scaler arrays. Data
may be moved, counted, or, in some way, reworked. Most of them have a cousin
for strings, flex strings, types, etc. but there are times when it is easier
to work with 32bit pointers and as pointers simply point to data and have no
real relationship with their data type you can do some pretty neat stuff BUT
you are in charge and if you blow it you can do a real tap dance on the data
in memory.
For our purposes here I will work with the QCopyXXX family of routines. This
set has all the above mentioned members and will show just exactly what kind
of tricks can be pulled when you use pointers.
QCopyARR used to have 3 alias' QCopyARR2PTR, QCopyPTR2ARR, and QCopyPTR2PTR.
They were all the same .ASM routine but to get PowerBASIC to work with our
version of 32bit pointers we had to declare each of them differently:
DECLARE SUB QCopyARR2PTR (SEG ANY, BYVAL T???,BYVAL Bytes%)
DECLARE SUB QCopyPTR2ARR (BYVAL F???,SEG ANY, BYVAL Bytes%)
DECLARE SUB QCopyPTR2PTR (BYVAL F???,BYVAL T???,BYVAL Bytes%)
Notice the similarity in how PowerBASIC now accepts pointers? This is no
coincidence as when you pass a scaler variable by SEG you are, in fact,
only pushing the 32bit pointer onto the stack so memory can be directly
addressed, read and/or changed. <<<BUT>>> when you pass any of the strings
by SEG you are passing only the string handle and NOT the pointer so be
careful that you use this little pointer trick in place of scaler arrays
and not strings!
$endif
OPTION BASE 0
'┌──────────────────────────────
$INCLUDE "DAS-NB01.INC" '│ None of the uses for QCopyXXX
COLOR 7, 0 '│ below are "normal". They have
CLS '│ all been tricked into doing
'│ work they were not designed
DIM A?(10) '│ to do by passing pointers
S$ = SPACE$(11) '│
D$ = "HELLO WORLD" '│
'│
Aptr??? = VARPTR32( A?(0) ) '│ 32bit pointers to the 3 vars
Sptr??? = STRPTR32( S$ ) '│ note we are using only the
Dptr??? = STRPTR32( D$ ) '│ values and don't have to
'│ declare the vars as PTRs
'│
QCopyARR BYVAL Dptr???, BYVAL Sptr???, 11 '│ this should be array to array
PRINT "S$ NOW EQUALS: "; S$ '│ but we are copying string to
PRINT '│ string
'│
QCopyARR BYVAL Dptr???, BYVAL Aptr???, 11 '│ now we are going from string
PRINT "AND HERE ARE THE ASCII VALUES" '│ to array
FOR X% = 0 TO 10 '│
PRINT USING "##_, "; A?(X%); '│
NEXT '│
PRINT : PRINT '│
'│
N$ = fQcopy$( BYVAL Aptr???, 11 ) '│ from an array into a string
PRINT "fCopy$ makes a copy of memory: "; N$ '│
PRINT '│
'│
Z$ = "XXXXXXXXXXX" '│ and, finally from a string
QCopySTR Z$, BYVAL Sptr??? '│ back into a string
PRINT S$ '│
'└──────────────────────────────